﻿using System;
using System.Collections.Generic;
using T.ServiceComponent.I18N.SPI;
using T.FAS.Runtime.Base.Entity;
using T.FAS.Runtime.Term.Entity;
using T.FAS.Runtime.Term.Service;
using T.FAS.Runtime.Term.SGSPI;
using T.ServiceComponent.Kernel.Service;

namespace T.FAS.Runtime.Term.SGPlugin
{
    public class PageRefService : IPageRefService
    {
        readonly PageRefManager manager = new PageRefManager();
        /// <summary>
        /// 获取Page脚本版本
        /// </summary>
        /// <returns></returns>
        [SGService(ServiceID = "FASR-GetPageVerMask", Describtion = "同步词条", ServiceType = ServiceType.Retrieve)]
        public long GetPageVerMask(string pageId, string language)
        {
            if (string.IsNullOrEmpty(pageId))
                throw new FasException(TermExceptionCode.InValidParam, "PageRefService.GetPageVerMask.pageId");
            return manager.GetPageVerMask(pageId, language);
        }
        /// <summary>
        /// 获取公共js新版本
        /// </summary>
        /// <returns></returns>
        public long GetCommonVerMask(string language)
        {
            return manager.GetCommonVerMask();
        }
        /// <summary>
        /// 根据词条编号获取词条
        /// </summary>
        /// <returns></returns>
        public I18NTerm GetTermBycode(string termCode)
        {
            return new I18NTerm();
        }
        /// <summary>
        /// 根据词条编号集合获取词条集合
        /// </summary>
        /// <returns></returns>
        public List<I18NPageTermMapping> GetTermsBycodes(List<string> termCodeList)
        {
            return manager.GetTermsBycodes(termCodeList);
        }
        /// <summary>
        /// 运行时修改词条，重新生成PageJS 
        /// </summary>
        public void UpdateTermMappings(List<I18NPageTermMapping> i18NPageTerms)
        {
            manager.UpdateTermMappings(i18NPageTerms);//更新词条信息
        }
        /// <summary>
        /// 重新生成所有JS
        /// </summary>
        /// <param name="i18NID"></param>
        public void RegenerationAll()
        {
            manager.RegenerationAll();
        }
        /// <summary>
        /// 根据翻译项生成JS
        /// </summary>
        /// <param name="i18NID"></param>
        public void RegenerationJS(List<string> termMappingIDs)
        {
            manager.RegenerationJS(termMappingIDs);
        }
        /// <summary>
        /// 根据分支生成JS
        /// </summary>
        /// <param name="i18NID"></param>
        public void RegenerationBranchJS(string branchID)
        {
            manager.RegenerationBranchJS(branchID);
        }
        /// <summary>
        /// 根据分支生成JS
        /// </summary>
        /// <param name="i18NID"></param>
        public void RegenerationJSBySource(List<string> sourceIDs)
        {
            manager.RegenerationJSBySource(sourceIDs);
        }
        /// <summary>
        ///  运行时修改词条，重新生成PageJS
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, string> UpdateTerms(List<CustomTerm> i18NTermItems)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("state", "1");
            return dic;
        }
    }
}
